package com.server.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.server.pojo.AdminNotifications;
import com.server.pojo.Entries;
import com.server.service.EntriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 知识百科词条表 前端控制器
 * </p>
 *
 * @author ckick
 * @since 2025-09-20 09:29:27
 */
@RestController
public class EntriesController {
    @Autowired
    EntriesService entriesService;
    @Autowired
    AdminNotificationsController adminNotificationsController;

    @RequestMapping("epage")
    IPage<Entries> epageQuery(@RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "5") Integer limit){
        return entriesService.getEntriesWithUserAndCategory(page, limit);
    }

    @RequestMapping("removeByEid")
    Boolean del(Integer entryId){
        return entriesService.removeById(entryId);
    }

    @RequestMapping("removeByEids")
    Boolean dels(@RequestBody List<Integer> entryIds) {
        return entriesService.removeByIds(entryIds);
    }

    @RequestMapping("updateStatus")
    Boolean updateStatus(@RequestParam Integer entryId, @RequestParam String status) {
        Entries entries = new Entries();
        entries.setEntryId(entryId);
        entries.setStatus(status);
         if (entriesService.updateById(entries)){
             return adminNotificationsController.systemNotification(entryId,status);
         }
         return false;
    }

}
